import axios from '@/request';

interface User {
  id: number;
  name: string;
  age: number;
}

/**
 * 获取所有用户
 */
export const getUsers = () => {
  return axios('/api/users', {
    method: 'GET',
  });
}

/**
 * 添加用户
 */
export const addUser = (user: User) => {
  return axios('/api/users', {
    method: 'POST',
    data: user,
  });
}

/**
 * 
 * @param id 
 * @returns 
 */
export const deleteUser = (id: number) => {
  return axios(`/api/users/${id}`, {
    method: 'DELETE',
  });
}
/**
 * 更新用户
 */
export const updateUser = (user: User) => {
  return axios(`/api/users/${user.id}`, {
    method: 'PUT',
    data: user,
  });
}

/**
 * 获取用户详情
 */
export const getUser = (id: number) => {
  return axios(`/api/users/${id}`, {
    method: 'GET',
  });
}